package top.pushmy

class MyTree<T>(
	var data: T,
	var children: ArrayList<MyTree<T>>? = null,
	var parentNode: MyTree<T>? = null
) {


	fun isRoot(): Boolean {
		if (parentNode == null) {
			return true
		}
		return false
	}

	fun getRoot(): MyTree<T> {

		if (isRoot()) {
			return this
		} else {
			var root = parentNode
			while (!root!!.isRoot()) {
				root = root.parentNode

			}
			return root

		}
	}

	fun getParent(): MyTree<T>? {
		if (parentNode == null) {
			return null
		} else {
			return parentNode
		}

	}

	fun getAllNode() {

		var root = getRoot()
		root.children?.forEach { println() }


	}


}